Programming Examples

Write a program that takes two integers m and n (where m < n) as input and computes the sum of all even numbers between m and n (inclusive). Use the pass statement for numbers that are not even.


Write a program that takes two integers m and n (where m < n) as input and computes the sum of all even numbers between m and n (inclusive). Use the pass statement for numbers that are not even.

Solution

m = int(input("Enter value of m: "))
n = int(input("Enter value of n: "))

total = 0

for i in range(m, n + 1):
    if i % 2 != 0:
        pass   # Skip odd numbers
    else:
        total += i

print("Sum of even numbers =", total)
▶ RUN

Output/ Explanation:

Enter value of m: 1

Enter value of n: 10

Sum of even numbers = 30


Latest Current Affairs 2026 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad